// @ 表示的是 src 目录的绝对路径
// import Home from '@/views/home'
// import Category from '@/views/category'
// import SubCategory from '@/views/category/SubCategory'
// import List from '@/views/list'
// import Cart from '@/views/cart'
// import Confirm from '@/views/confirm'
// import Mine from '@/views/mine'
// import Detail from '@/views/detail'
// import Login from '@/views/login'
// import NavBar from '@/components/nav-bar'
// import TabBar from '@/components/tab-bar'

// 异步引入组件：路由懒加载
const Home = () => import('@/views/home')
const Category = () => import('@/views/category')
const SubCategory = () => import('@/views/category/SubCategory')
const List = () => import('@/views/list')
const Cart = () => import('@/views/cart')
const Confirm = () => import('@/views/confirm')
const Mine = () => import('@/views/mine')
const Detail = () => import('@/views/detail')
const Login = () => import('@/views/login')
const NavBar = () => import('@/components/nav-bar')
const TabBar = () => import('@/components/tab-bar')

/**
 * 路由配置
 */
const routes = [
  {
    path: '/',
    redirect: '/home',
  },
  {
    path: '/home', // 路径
    components: { // 命名视图
      default: Home,
      footer: TabBar,
    },
    meta: { // 路由元信息，开发过程中要使用到与当前路由相关的数据
      title: '首页',
      icon: '&#xe6b8;',
      inTabBar: true,
    },
  },
  {
    path: '/category',
    components: {
      header: NavBar,
      default: Category,
      footer: TabBar,
    },
    children: [ // 子路由，嵌套路由
      {
        path: 'sub-category/:id', // 完整路径：/category/sub-category
        name: 'sub',
        component: SubCategory,
        meta: {
          title: '子分类',
        },
      },
    ],
    meta: {
      title: '分类',
      icon: '&#xe729;',
      inTabBar: true,
    },
  },
  {
    path: '/cart',
    components: {
      header: NavBar,
      default: Cart,
    },
    meta: {
      title: '购物车',
      icon: '&#xe6af;',
      inTabBar: true,
    },
  },
  {
    path: '/list',
    components: {
      header: NavBar,
      default: List,
    },
    meta: {
      title: '商品列表',
    },
  },
  {
    path: '/mine',
    components: {
      header: NavBar,
      default: Mine,
      footer: TabBar,
    },
    meta: {
      title: '我的',
      icon: '&#xe736;',
      inTabBar: true,
    },
  },
  {
    // path: '/detail',
    path: '/detail/:id', // 定义动态路径参数
    name: 'detail', // 命名路由
    components: {
      default: Detail,
    },
    meta: {
      title: '商品详情',
    },
  },
  {
    path: '/login',
    name: 'login',
    components: {
      header: NavBar,
      default: Login,
    },
    meta: {
      title: '登录',
    },
  },
  {
    path: '/confirm',
    components: {
      header: NavBar,
      default: Confirm,
    },
    meta: {
      title: '确认订单',
    },
  },
]

export default routes
